package com.example.finalapplication;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class MyTask implements Runnable {
    private static final String TAG = "MyTask";
    private Handler handler;

    public void setHandler(Handler handler) {

        this.handler = handler;
    }

    @Override
    public void run() {
        //获取网络数据
        ArrayList<String> List = new ArrayList<String>();
        try {
            Log.i(TAG, "run: running......");
            Document doc = Jsoup.connect("https://www.boohee.com/food/").get();
            Log.i(TAG, "run: title=");
            Elements lis = doc.getElementsByTag("li");
            for (Element li : lis) {
                Elements h3 = li.getElementsByTag("h3");
                String td1 = h3.text();
                Log.i(TAG, "run: " + td1);
//                HashMap<String,String> map = new HashMap<>();
//                map.put("Food",td1);
                Log.i(TAG, "run: food");
                List.add(td1);

            }

            Message msg = handler.obtainMessage(5, List);
            //    msg.what = 7;
            //    msg.obj = "hello from msg";
            handler.sendMessage(msg);
            Log.i(TAG, "run: sendMessage OK");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}